package com.cheer.controller;

import com.cheer.service.AuthService;
import com.cheer.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 身份认证API
 */
@RestController
@RequestMapping("/auth")
@Slf4j
public class AuthController {

    @Autowired
    private AuthService authService;

    /**
     * 获取验证码
     */
    @GetMapping("/captcha")
    public void getCaptcha(@RequestParam(required = false) Integer width,
                           @RequestParam(required = false) Integer height,
                           @RequestParam Integer type) {
        authService.getCaptcha(width, height, type);
    }

    /**
     * 登录是否需要验证码
     */
    @GetMapping("/required")
    public Result<Boolean> isCaptchaRequired() {
        Boolean required = authService.isLoginCaptchaRequired();
        return Result.success(required);
    }

}
